﻿using System.Web.Mvc;
using System.Web;

namespace ASPItalia.ModelVirtualCasting.Web.Utils
{
    public class SkinnableViewEngine : WebFormViewEngine
    {
        public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
        {
            string skinViewName = viewName;

            if (controllerContext.HttpContext.Request.Browser.IsMobileDevice)
            {
                skinViewName = "Mobile/" + viewName;
            }

            var res = base.FindView(controllerContext, skinViewName, masterName, useCache);

            if (res.View == null)
                return base.FindView(controllerContext, viewName, masterName, useCache);
            
            return res;
        }

    }
}